import { createStore, Store, useStore as useVuexStore } from 'vuex'

import { IRootState, IRootType } from './types'

import loginModule from './login/login'

// 创建一个新的 store 实例
const store = createStore<IRootState>({
  state() {
    return {
      name: 'chen',
      age: 18
    }
  },
  mutations: {},
  modules: {
    loginModule
  }
})

export function setupStore() {
  store.dispatch('loginModule/loadLocalLogin')
}

export function useStore(): Store<IRootType> {
  return useVuexStore()
}

export default store
